#include <stdio.h>
#include <string.h>

struct Contact {
    char name[11];
    char birthday[9];
    char phone[18];
};

int main() {
    int n;
    scanf("%d", &n);
    struct Contact c[10];
    for (int i = 0; i < n; i++) {
        scanf("%s %s %s", c[i].name, c[i].birthday, c[i].phone);
    }
    for (int i = 0; i < n - 1; i++) {
        int maxIdx = i;
        for (int j = i + 1; j < n; j++) {
            if (strcmp(c[j].birthday, c[maxIdx].birthday) < 0)
                maxIdx = j;
        }
        if (maxIdx != i) {
            struct Contact temp = c[i];
            c[i] = c[maxIdx];
            c[maxIdx] = temp;
        }
    }
    for (int i = 0; i < n; i++) {
        printf("%s %s %s\n", c[i].name, c[i].birthday, c[i].phone);
    }
    return 0;
}
